/*
 *  Copyright 2024 Collate.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  http://www.apache.org/licenses/LICENSE-2.0
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

@import '../../styles/variables.less';

.knowledge-graph-container {
  height: 100%;
  position: relative;

  .knowledge-graph-controls {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.98);
    padding: 8px 12px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 0, 0, 0.08);

    .ant-select {
      min-width: 120px;
      height: 32px;

      .ant-select-selector {
        height: 32px;
        border-radius: 8px !important;
        border-color: #e8e8e8;
        display: flex;
        align-items: center;

        &:hover {
          border-color: #d9d9d9;
        }
      }
    }

    .ant-btn {
      height: 32px;
      border-radius: 8px;
      transition: all 0.2s ease;
      border-color: #e8e8e8;
      display: inline-flex;
      align-items: center;
      justify-content: center;

      &:hover {
        transform: translateY(-1px);
        box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
        border-color: #d9d9d9;
      }

      &:active {
        transform: translateY(0);
      }
    }

    .ant-space-compact {
      display: flex;
      align-items: center;
    }

    .depth-slider-container {
      display: flex;
      align-items: center;
      gap: 8px;
      min-width: 200px;

      .depth-label {
        font-size: 13px;
        color: #595959;
        white-space: nowrap;
        font-weight: 500;
      }

      .depth-slider {
        flex: 1;
        margin: 0 8px;

        .ant-slider-track {
          background-color: #1890ff;
        }

        .ant-slider-handle {
          border-color: #1890ff;

          &:hover {
            border-color: #40a9ff;
          }

          &:focus {
            border-color: #40a9ff;
            box-shadow: 0 0 0 5px rgba(24, 144, 255, 0.12);
          }
        }

        .ant-slider-mark-text {
          font-size: 11px;
          color: #8c8c8c;
        }

        .ant-slider-dot {
          border-color: #d9d9d9;

          &.ant-slider-dot-active {
            border-color: #1890ff;
          }
        }
      }
    }
  }

  .knowledge-graph-canvas {
    height: calc(100vh - 250px);
    min-height: 600px;
    border: none;
    border-radius: 16px;
    background: #f5f5f5;
    background-image: radial-gradient(circle, #e8e8e8 1px, transparent 1px);
    background-size: 20px 20px;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.04),
      0 0 0 1px rgba(0, 0, 0, 0.05);

    // Vis.js network specific styling
    .vis-network {
      width: 100% !important;
      height: 100% !important;

      canvas {
        outline: none !important;
      }
    }

    // Tooltip styling
    .vis-tooltip {
      position: absolute;
      visibility: hidden;
      padding: 8px 12px;
      font-size: 13px;
      background-color: rgba(0, 0, 0, 0.85);
      color: @white;
      border-radius: 6px;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
      pointer-events: none;
      z-index: 1000;
      max-width: 300px;

      &::after {
        content: '';
        position: absolute;
        bottom: -4px;
        left: 50%;
        transform: translateX(-50%);
        width: 0;
        height: 0;
        border-left: 4px solid transparent;
        border-right: 4px solid transparent;
        border-top: 4px solid rgba(0, 0, 0, 0.85);
      }
    }
  }

  .ant-card {
    height: 100%;
    border-radius: 16px;
    overflow: visible;
    border: 1px solid #f0f0f0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);

    .ant-card-head {
      background: #fff;
      border-bottom: 1px solid #f0f0f0;
      padding: 18px 24px;

      .ant-card-head-title {
        font-size: 18px;
        font-weight: 600;
        color: #262626;
      }
    }

    .ant-card-body {
      padding: 16px;
      height: calc(100% - 73px);
      position: relative;
      background: #fff;
    }
  }

  // Loading and empty states
  .knowledge-graph-loading,
  .knowledge-graph-empty {
    height: 600px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fafbfc;
    border-radius: 16px;

    .ant-spin {
      .ant-spin-dot {
        font-size: 32px;
      }
    }

    .ant-empty {
      .ant-empty-description {
        color: #8c8c8c;
      }
    }
  }

  // Minimap styling
  .knowledge-graph-minimap {
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 150px;
    height: 150px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(10px);
    overflow: hidden;
    z-index: 999;
  }

  // Node details panel
  .knowledge-graph-node-details {
    position: absolute;
    top: 16px;
    left: 16px;
    width: 320px;
    max-height: calc(100% - 32px);
    background: rgba(255, 255, 255, 0.98);
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    z-index: 1001;
    overflow: hidden;
    transition: all 0.3s ease;

    .node-details-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 12px 16px;
      border-bottom: 1px solid #f0f0f0;

      .ant-typography {
        margin-bottom: 0;
      }
    }

    .node-details-content {
      padding: 16px;
      overflow-y: auto;
      max-height: calc(100vh - 200px);

      .ant-typography-secondary {
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
      }
    }
  }

  // Hover effects for nodes (vis-network styling)
  .vis-network:hover {
    cursor: grab;
  }

  .vis-network:active {
    cursor: grabbing;
  }

  // Custom hover tooltip
  .knowledge-graph-hover-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 10px 14px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    pointer-events: none;
    max-width: 300px;
    animation: fadeIn 0.2s ease;

    .hover-tooltip-content {
      .hover-tooltip-title {
        font-size: 14px;
        font-weight: 600;
        margin-bottom: 4px;
      }

      .hover-tooltip-type {
        font-size: 12px;
        color: #b8b8b8;
        margin-bottom: 2px;
      }

      .hover-tooltip-fqn {
        font-size: 11px;
        color: #999;
        word-break: break-word;
      }
    }

    &::after {
      content: '';
      position: absolute;
      bottom: -4px;
      left: 50%;
      transform: translateX(-50%);
      width: 0;
      height: 0;
      border-left: 5px solid transparent;
      border-right: 5px solid transparent;
      border-top: 5px solid rgba(0, 0, 0, 0.9);
    }
  }

  @keyframes fadeIn {
    from {
      opacity: 0;
      transform: translateY(-5px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  // Disable vis.js default tooltips
  .vis-tooltip {
    display: none !important;
  }

  // Fullscreen mode styles
  &:fullscreen,
  &:-webkit-full-screen,
  &:-moz-full-screen,
  &:-ms-fullscreen {
    background: #f5f5f5;
    padding: 0;

    .knowledge-graph-canvas {
      height: 100vh;
      border-radius: 0;
      max-height: none;
      margin: 0;
      background: #f5f5f5;
    }

    .ant-card {
      height: 100vh;
      border-radius: 0;
      border: none;
      box-shadow: none;
      background: transparent;

      .ant-card-head {
        display: none;
      }

      .ant-card-body {
        height: 100vh;
        padding: 0;
      }
    }

    .knowledge-graph-controls {
      top: 16px;
      right: 16px;
    }

    .knowledge-graph-node-details {
      top: 16px;
    }
  }
}
